package com.example.mobile2121606110syc0430homework;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.lang.annotation.Native;

public class PartRViewAdapter extends RecyclerView.Adapter<PartRViewAdapter.ViewHolder>{
    private int[] partId;
    private String[] partName;
    private String[] partName2;
    public PartRViewAdapter(int[] partId,String[] partName,String[] partName2){
        this.partId = partId;
        this.partName = partName;
        this.partName2 = partName2;
    }
    static class ViewHolder extends RecyclerView.ViewHolder{
        ImageView imageView;
        TextView textView;
        TextView textView2;
        public ViewHolder(@NonNull View itemView){
            super(itemView);
            this.imageView = itemView.findViewById(R.id.ivItemPart);
            this.textView = itemView.findViewById(R.id.tvItemPart);
            this.textView2 = itemView.findViewById(R.id.tvItemPart2);
        }
    }
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent,int viewType){
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_rv_main_part,null);
        ViewHolder viewHolder=new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.imageView.setImageResource(partId[position]);
        holder.textView.setText(partName[position]);
        holder.textView2.setText(partName2[position]);
    }
    @Override
    public int getItemCount(){
        return partId.length;
    }
}
